<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <!--必要样式-->
    <link rel="stylesheet" type="text/css" href="css/component.css" />
    <script type="text/css">
        body
        {
            background-color:yellow;
        }
    </script>
    <script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="js/jquery.cookie-1.4.1.min.js"></script>
    <script type="text/javascript">
        $(function () {
            var CARD_Balance_URL="http://localhost:8080/card/getBalance/";
            var userno=$.cookie("userno");
            $.ajax({
                url:CARD_Balance_URL+userno,
                type:"POST",
                statusCode:{
                    200:function (data) {
                      $("#balance").html(data);
                    }
                }
            })
        });
        function chongZhi(obj) {
            var chongzhi1=obj.value;
            var balance=$("#balance").html();

            var CARD_ChongZhi_URL="http://localhost:8080/card/chongZhi/";
            var userno=$.cookie("userno");
            var length=chongzhi1.length;
            balance=parseInt(balance)+parseInt(chongzhi1.substring(0,length-1));
            $.ajax({
                url:CARD_ChongZhi_URL+userno+"/"+balance,
                type:"POST",
                statusCode:{
                    200:function () {
                        alert("恭喜您，充值成功！！！");
                        window.location="chongZhi.html";
                    }
                }
            })
        }
    </script>
</head>
<body bgcolor="#f2f0f5">
    <h1>校园卡充值中心</h1>
    <br/>
    <div align="center">
        <h1>您的余额为:<span id="balance"></span></h1>
    </div>
    <br/><br/><br/><br/><br/><br/><br/><br/>
    <div class="mb2" align="right">
        <input type="button" id="chongzhi50" class="act-but submit"
               onclick="chongZhi(this)" style="color: #FFFFFF;width:10%;" value="50元"/>
    </div>
    <div class="mb2" align="right">
        <input type="button" id="chongzhi100" class="act-but submit"
               onclick="chongZhi(this)" style="color: #FFFFFF;width:10%;" value="100元"/>
    </div>
</body>
</html>